<?php 
	/**
	 * 对象串行化
	 */

	class Person {
		public $name = "";
		public $age  = 18;
		public $sex  = "男";
		public $marr = array(
			"aaa",
			"bbb",
			"ccc",
			"ddd"
		);

		public function __construct($name, $age, $sex) {
			$this->name = $name;
			$this->age  = $age;
			$this->sex  = $sex;
		}

		public function say() {
			echo "我叫".$this->name;
		}

		public function __toString() {
			echo "Hello!!!";
		}

		public function __call($method, $args) {
			if (in_array($method, $this->marr)) {
				echo $args[0]."<br>";
			}else{
				echo "你调用的方法{$method}()不存在！<br>";
			}

			/*echo "对不起！你调用的方法{$method}(),参数为";
			print_r($args);
			echo "不存在！<br>";*/
		}

		public function __sleep(){
			echo "这是执行串行化时自动调用的方法<br>";
			echo "只串行化name和age<br>";

			return array("name", "age");
		}
	}

	//对象
	$p1 = new Person("张三", 20, "男");

	//将对象串行化
	$str = serialize($p1);

	//将串行化数组存入文档中
	file_put_contents("22-objstr.txt", $str);

	echo "对象转完字符串，保存文件成功！！<br>";












 ?>